package com.example.activity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Rain on 2016/4/15.
 */
public class Myadapter extends BaseAdapter{
    private Context ctx;
    private List<Map<String,Object>> values;

    public Myadapter(List<Map<String, Object>> values, Context ctx) {
        this.values = values;
        this.ctx = ctx;
    }

    @Override
    public int getCount() {
        return values.size();
    }

    @Override
    public Object getItem(int position) {
        return values.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            convertView = LayoutInflater.from(ctx).inflate(R.layout.list_new_line,null);
            convertView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,Globals.SCREEN_HEIGHT/10));
            TextView img = (TextView) convertView.findViewById(R.id.img);
            TextView fileName = (TextView) convertView.findViewById(R.id.fileName);
            Map<String,Object> map = values.get(position);
            fileName.setText(map.get("fileName").toString());
            img.setBackgroundResource(Globals.imgs.get(map.get("exName")));
            img.getLayoutParams().height=Globals.SCREEN_HEIGHT/10;
        }
        return convertView;
    }
}
